import java.rmi.MarshalException;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/8 11:02
 * @Copyright 博为峰
 */
public class ArrayTest01 {
    public static void main(String[] args) {
        //最值
        int[] arr = {10, 21, 9, 11, 26, 6};

//        int max = arr[0];
//        for (int i = 0; i < arr.length; i++) {
//            if (arr[i] > max) {
//                max = arr[i];
//            }
//        }

//        System.out.println("max = " + max);
        //选择排序
        int t;
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[i] > arr[j]) {
                    t = arr[i];
                    arr[i] = arr[j];
                    arr[j] = t;
                }
            }
        }
        //冒泡排序
//        for (int i = 0; i < arr.length - 1; i++) {
//            for (int j = 0; j < arr.length - i - 1; j++) {
//                if (arr[j] > arr[j + 1]) {
//                    t = arr[j];
//                    arr[j] = arr[j + 1];
//                    arr[j + 1] = t;
//                }
//            }
//        }

//        for (int i : arr) {
////            System.out.println("i = " + i);
//        }

        //查找
        int f = 26;
        int min = 0;
        int max = arr.length - 1;
        int mid = (min + max) / 2;

        while (arr[mid] != f) {
            if (f > arr[mid]) {
                min = mid + 1;
            }

            if (f < arr[mid]) {
                max = mid - 1;
            }

            if(max < min ){
                mid = -1;
                break;
            }

            mid = (min + max) /2;
        }
    }
}
